package org.aarboard.nextcloud.api.dicom;

import ij.plugin.DICOM;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * Created by Enzo Cotter on 2022/7/8.
 */
// ================================pom============================
//<!-- https://mvnrepository.com/artifact/imagej/ij -->
//<dependency>
//<groupId>ij</groupId>
//<artifactId>ij</artifactId>
//<version>1.0</version>
//<scope>system</scope>
//<systemPath>D:/迅雷下载/ij.jar</systemPath>
//</dependency>
//导不进去就引入本地的jar

public class imageJTest {

    public static void main(String[] args) throws Exception {

        File folderFile = new File("hanby");
        String dcmFile = "D:\\hanby\\ImageJDemo-master\\ImageJDemo-master\\image\\test1.dcm";
        //dcm2JpgByImageJ(dcmFile, folderFile);

        create2(dcmFile);
    }

    private static void create(String fileName) {
        try {
            String projectPath = System.getProperty("user.dir");
            //Check class DICOM
            DICOM dicom = new DICOM();
            String imagePath = projectPath + "\\image\\" + fileName;
            dicom.run(imagePath);
            BufferedImage bi = (BufferedImage) dicom.getImage();
            int width = bi.getWidth();
            int height = dicom.getHeight();
            System.out.println("width: " + width + "\n" + "height: " + height);
            imagePath = projectPath + "\\image\\" + fileName + ".jpg";
            ImageIO.write(bi, "jpg", new File(imagePath));
            System.out.println("Hehe,Game over!!!");

        } catch (Exception e) {
            System.out.println("错误" + e.getMessage());
        }

    }


    /**
     * 输入一个dicom文件的绝对路径和名字
     * 获取一个jpg文件
     */
    private static void create2(String filePath) {
        try {
            DICOM dicom = new DICOM();
            dicom.run(filePath);
            BufferedImage bi = (BufferedImage) dicom.getImage();
            int width = bi.getWidth();
            int height = dicom.getHeight();
            System.out.println("width: " + width + "\n" + "height: " + height);
            String imagePath = filePath + ".jpg";
            ImageIO.write(bi, "jpg", new File(imagePath));
            System.out.println("Hehe,Game over!!!");

        } catch (Exception e) {
            System.out.println("错误" + e.getMessage());
        }

    }

}
